package com.chj.comp.service.demo1.controller;

import com.chj.comp.common.core.util.Result;
import com.chj.comp.service.demo1.service.IExcelTestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cuihui
 * @since 2022-04-16
 */
@RestController
@RequestMapping("/excel")
@Api(tags = "excel测试接口")
@Slf4j
public class ExcelTestController {

    @Autowired
    private IExcelTestService excelTestService;

    /**
     * excel模板下载
     */
    @GetMapping("/downloadDemo")
    @ApiOperation(value = "excel模板下载")
    public void downloadDemo(HttpServletResponse response) throws IOException {
        excelTestService.downloadDemo(response);
    }

    /**
     * excel数据下载
     */
    @GetMapping("/downloadData")
    @ApiOperation(value = "excel数据下载")
    public void downloadData(HttpServletResponse response) throws IOException {
        excelTestService.downloadData(response);
    }

    /**
     * excel导入
     */
    @PostMapping("/uploadData")
    @ApiOperation(value = "excel导入")
    @ResponseBody
    public Result uploadData(MultipartFile file) throws IOException {
        return excelTestService.uploadData(file);
    }
}
